Skip to content

Add OpenAPI 3.0 specification for API v2#57

Merged
renecannao merged 1 commit intomasterfrom
issue54-openapi-spec
Mar 24, 2026
Merged

Add OpenAPI 3.0 specification for API v2#57
renecannao merged 1 commit intomasterfrom
issue54-openapi-spec

Conversation

@renecannao
Copy link
Copy Markdown

@renecannao renecannao commented Mar 24, 2026

Summary

  • Add a complete OpenAPI 3.0 spec at docs/api/openapi.yaml covering all 9 v2 API endpoints with request parameters, response schemas, examples, and error definitions.
  • Update docs/api-v2.md to reference the new OpenAPI spec file.

Closes #54

Test plan

  • Validate YAML parses correctly: python3 -c "import yaml; yaml.safe_load(open('docs/api/openapi.yaml'))"
  • Load spec in Swagger UI or Redoc to verify rendering
  • Confirm all 9 endpoints match routes in go/http/apiv2.go

Summary by CodeRabbit

Documentation

  • Added formal OpenAPI 3.0 specification for the Orchestrator API v2 with comprehensive endpoint definitions, request/response schemas, and example payloads.
  • Specification is fully compatible with standard API documentation tools including Swagger UI, Redoc, and code generation utilities.
  • Enhanced API documentation with machine-readable OpenAPI reference to support improved developer tooling integration.

Provide a machine-readable OpenAPI spec covering all 9 v2 endpoints
with request/response schemas, examples, and error definitions.
Update api-v2.md to reference the new spec file.

Closes #54
Copilot AI review requested due to automatic review settings March 24, 2026 11:54
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the API documentation by introducing a machine-readable OpenAPI 3.0 specification for the v2 API. This addition will improve the developer experience by providing a standardized and easily consumable format for understanding and integrating with the API, enabling automated client generation and interactive documentation tools.

Highlights

  • OpenAPI Specification Added: A comprehensive OpenAPI 3.0 specification has been added at docs/api/openapi.yaml, covering all nine v2 API endpoints with detailed request parameters, response schemas, examples, and error definitions.
  • Documentation Update: The docs/api-v2.md file has been updated to include a reference to the newly added OpenAPI specification, enhancing discoverability for API consumers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

This change adds comprehensive API documentation by creating a new OpenAPI 3.0.3 specification file for Orchestrator API v2 and adding a reference to it in the existing API documentation.

Changes

Cohort / File(s) Summary
API Documentation
docs/api-v2.md, docs/api/openapi.yaml
Introduced OpenAPI 3.0.3 specification for Orchestrator API v2 covering 9 endpoints (/clusters, /instances, /recoveries, /status, /proxysql/servers with variants). Includes complete request/response schemas using V2APIResponse envelope, reusable components (ClusterInfo, Instance, HealthStatus, etc.), and example payloads. Updated main API docs to reference the new spec.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 Hoppy hops through specs so bright,
OpenAPI paths, now documented right!
Nine endpoints hop into the light,
Swagger and Redoc make devs delight!
From clusters to servers, the API's in sight! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding an OpenAPI 3.0 specification for API v2, which matches the primary objective of this changeset.
Linked Issues check ✅ Passed The PR fulfills all coding requirements from issue #54: creates docs/api/openapi.yaml with 9 endpoints, defines V2APIResponse schemas, includes examples and error definitions, and updates API v2 docs.
Out of Scope Changes check ✅ Passed All changes are directly related to the OpenAPI spec requirement: docs/api/openapi.yaml (648 lines) implements the spec, and docs/api-v2.md (+6 lines) references it. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue54-openapi-spec

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a comprehensive OpenAPI 3.0 specification for the API v2, significantly improving API documentation and enabling better tooling integration. The docs/api-v2.md file has been updated to reference this new specification, enhancing discoverability for users. The new OpenAPI definition covers all nine v2 API endpoints with detailed request parameters, response schemas, examples, and error definitions, which is a great step towards a more robust and user-friendly API.

Comment thread docs/api/openapi.yaml
items:
type: string
RecoveryStartTimestamp:
type: string
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For RecoveryStartTimestamp, consider using the format: date-time property and updating the example to an ISO 8601 compliant string (e.g., "2025-01-15T10:30:00Z"). This provides clearer guidance for API consumers and improves compatibility with OpenAPI tooling that expects standard date-time formats.

        RecoveryStartTimestamp:
          type: string
          format: date-time
          description: Timestamp when recovery started.
          example: "2025-01-15T10:30:00Z"

Comment thread docs/api/openapi.yaml
description: Timestamp when recovery started.
example: "2025-01-15 10:30:00"
RecoveryEndTimestamp:
type: string
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to RecoveryStartTimestamp, it would be beneficial to use format: date-time for RecoveryEndTimestamp and provide an ISO 8601 compliant example. This ensures consistency and adherence to common API best practices for date-time representation.

        RecoveryEndTimestamp:
          type: string
          format: date-time
          description: Timestamp when recovery ended.
          example: "2025-01-15T10:30:45Z"

Comment thread docs/api/openapi.yaml
Comment on lines +600 to +604
type: object
properties:
Hostname:
type: string
example: "orchestrator-1"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ActiveNode schema in HealthStatus currently only includes Hostname. However, the Go process.NodeHealth struct (which ActiveNode represents) contains additional fields like Token and AppVersion. If these fields are relevant for API consumers, consider expanding the ActiveNode schema to include them for a more complete representation of the active node's health information.

        ActiveNode:
          type: object
          properties:
            Hostname:
              type: string
              example: "orchestrator-1"
            Token:
              type: string
              example: "abc123"
            AppVersion:
              type: string
              example: "2.0.0"

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an OpenAPI 3.0 specification for Orchestrator API v2 and links it from the existing v2 API documentation, enabling easier client generation and interactive API browsing.

Changes:

  • Added docs/api/openapi.yaml documenting the 9 /api/v2 endpoints, including schemas and examples.
  • Updated docs/api-v2.md to reference the new OpenAPI spec.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/api/openapi.yaml Introduces an OpenAPI 3.0.3 spec for all API v2 endpoints, including shared response envelope and component schemas.
docs/api-v2.md Adds a short “OpenAPI Specification” section linking to the new spec file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/api/openapi.yaml
Comment on lines +414 to +418
example:
status: error
error:
code: INTERNAL_ERROR
message: "An unexpected error occurred"
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared InternalServerError response example uses error code INTERNAL_ERROR, but the v2 handlers return endpoint-specific 500 codes (e.g. CLUSTER_LIST_ERROR, INSTANCE_READ_ERROR, TOPOLOGY_ERROR, RECOVERIES_ERROR, PROXYSQL_ERROR, UNHEALTHY). This makes the spec misleading for clients that rely on error.code. Suggest either (a) making the shared 500 response example/code generic (or omitting the example), or (b) defining per-endpoint 500 responses/examples with the actual codes returned by each handler.

Suggested change
example:
status: error
error:
code: INTERNAL_ERROR
message: "An unexpected error occurred"

Copilot uses AI. Check for mistakes.
Comment thread docs/api/openapi.yaml
Comment on lines +15 to +16
- url: /api/v2
description: Default (relative to orchestrator base URL, respects URLPrefix)
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

servers[0].url is set to /api/v2, but the actual router mounts v2 under config.Config.URLPrefix + "/api/v2" (see go/http/apiv2.go). As written, the generated clients/docs will be wrong when URLPrefix is non-empty. Consider using a server variable like {basePath}/api/v2 (with basePath defaulting to "" and documented as the configured URLPrefix), or listing two server entries to cover both cases.

Suggested change
- url: /api/v2
description: Default (relative to orchestrator base URL, respects URLPrefix)
- url: "{basePath}/api/v2"
description: Default v2 API base path. `basePath` should match the configured `URLPrefix` (empty if not set).
variables:
basePath:
default: ""
description: Base path prefix matching orchestrator config `URLPrefix` (leave empty if URLPrefix is not set).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
docs/api/openapi.yaml (2)

14-16: Consider adding explicit security documentation.

Static analysis flags missing security definitions (CKV_OPENAPI_4, CKV_OPENAPI_5). Even if the API intentionally requires no authentication (or relies on network-level security), it's best practice to document this explicitly:

♻️ Proposed fix to add explicit security declaration
 servers:
   - url: /api/v2
     description: Default (relative to orchestrator base URL, respects URLPrefix)
+
+security: []  # No authentication required; access controlled at network level

If authentication is planned or exists at another layer, consider adding the appropriate securitySchemes in components instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/api/openapi.yaml` around lines 14 - 16, The OpenAPI spec currently lacks
explicit security declarations; update docs/api/openapi.yaml to include either a
components.securitySchemes entry describing the auth method(s) used (e.g.,
bearerAuth, apiKey) and add a top-level security requirement, or explicitly
document no authentication by adding an empty security: [] at the root and a
clear comment under components explaining network-level/no-auth assumptions;
modify the file near the existing servers: block and add
components.securitySchemes and security entries so static analysis
(CKV_OPENAPI_4/5) no longer flags missing security.

36-39: Consider adding maxItems constraints to array schemas.

Static analysis (CKV_OPENAPI_21) flags that array types lack maxItems bounds. While not critical for documentation, adding limits can help API consumers understand expected cardinality and enables better client-side validation.

♻️ Example fix for the clusters array
                     data:
                       type: array
+                      maxItems: 1000
                       items:
                         $ref: "#/components/schemas/ClusterInfo"

This pattern could be applied to other arrays (instances, recoveries, RaftHealthyMembers, etc.) based on realistic operational limits.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/api/openapi.yaml` around lines 36 - 39, Add a maxItems constraint to the
array schema that currently defines "data" with items: $ref
"#/components/schemas/ClusterInfo" by updating that schema to include a sensible
maxItems value (e.g., based on expected cluster size) so clients and validators
have an upper bound; apply the same pattern to other array schemas such as those
named "instances", "recoveries", and "RaftHealthyMembers" where realistic
operational limits exist.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/api/openapi.yaml`:
- Around line 14-16: The OpenAPI spec currently lacks explicit security
declarations; update docs/api/openapi.yaml to include either a
components.securitySchemes entry describing the auth method(s) used (e.g.,
bearerAuth, apiKey) and add a top-level security requirement, or explicitly
document no authentication by adding an empty security: [] at the root and a
clear comment under components explaining network-level/no-auth assumptions;
modify the file near the existing servers: block and add
components.securitySchemes and security entries so static analysis
(CKV_OPENAPI_4/5) no longer flags missing security.
- Around line 36-39: Add a maxItems constraint to the array schema that
currently defines "data" with items: $ref "#/components/schemas/ClusterInfo" by
updating that schema to include a sensible maxItems value (e.g., based on
expected cluster size) so clients and validators have an upper bound; apply the
same pattern to other array schemas such as those named "instances",
"recoveries", and "RaftHealthyMembers" where realistic operational limits exist.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0598fbf9-549c-4f09-9ca0-e319d3902882

📥 Commits

Reviewing files that changed from the base of the PR and between 5740466 and 42e13cf.

📒 Files selected for processing (2)
  • docs/api-v2.md
  • docs/api/openapi.yaml

@renecannao renecannao merged commit 790f408 into master Mar 24, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI/Swagger specification for API v2

2 participants